<html>
<head><meta charset="utf-8"><title>Unsafe packed repr ref · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Unsafe.20packed.20repr.20ref.html">Unsafe packed repr ref</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202199684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Unsafe%20packed%20repr%20ref/near/202199684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Unsafe.20packed.20repr.20ref.html#202199684">(Jun 27 2020 at 18:49)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span>  so I've wrapped up all of the comments on the unsafe packed repr ref pr (<a href="https://github.com/rust-analyzer/rust-analyzer/pull/4743">https://github.com/rust-analyzer/rust-analyzer/pull/4743</a>), but I have one item I haven't done yet. In rustc, when it encounters these lines:</p>
<div class="codehilite"><pre><span></span><code><span class="kd">let</span><span class="w"> </span><span class="n">h</span><span class="w"> </span><span class="o">=</span><span class="w"> </span><span class="n">HasAligned</span><span class="p">{</span><span class="w"> </span><span class="n">a</span>: <span class="nc">NeedsAlign</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="n">a</span>: <span class="mi">1</span><span class="w"> </span><span class="p">}</span><span class="w"> </span><span class="p">};</span><span class="w"></span>
<span class="n">h</span><span class="p">.</span><span class="n">a</span><span class="p">.</span><span class="n">calls_autoref</span><span class="p">();</span><span class="w"></span>
</code></pre></div>


<p>It highlights <code>h.a</code> and points out that this method call causes an autoref which is an unsafe ref to a packed repr. Should I handle that in the current PR or as a follow-up? If we do tackle it, how would I even highlight it? Would it make sense to highlight the dot between the field expr and the method to call to signify that it's the call that's causing the issue, or do what rustc does and highlight <code>h.a</code>? But in the latter case, then should I create a new <code>HighlightTag::Expr</code> tag just for this case, or use <code>Operator</code>?</p>



<a name="202199901"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Unsafe%20packed%20repr%20ref/near/202199901" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Unsafe.20packed.20repr.20ref.html#202199901">(Jun 27 2020 at 18:54)</a>:</h4>
<p>I think we should higlightn <code>cals_autoref</code> as if it were an unsafe function?</p>



<a name="202200429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Unsafe%20packed%20repr%20ref/near/202200429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Unsafe.20packed.20repr.20ref.html#202200429">(Jun 27 2020 at 19:06)</a>:</h4>
<p>That makes sense, though I wonder if that would be really confusing since the method itself wouldn't be marked unsafe.</p>



<a name="202200599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Unsafe%20packed%20repr%20ref/near/202200599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Unsafe.20packed.20repr.20ref.html#202200599">(Jun 27 2020 at 19:10)</a>:</h4>
<p>I'm also realizing I need to account for <code>ref</code> and <code>&amp;</code> in bind patterns. Is it possible to determine the struct a field comes from when you're looking at a bind pattern? Or do I need to match on all patterns?</p>



<a name="202206116"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Unsafe%20packed%20repr%20ref/near/202206116" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Unsafe.20packed.20repr.20ref.html#202206116">(Jun 27 2020 at 21:38)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> accounting for ref and the auto ref method call nearly doubled the PR. I think it should be reviewed again, at least the additions</p>



<a name="202426146"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Unsafe%20packed%20repr%20ref/near/202426146" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Paul Faria <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Unsafe.20packed.20repr.20ref.html#202426146">(Jun 30 2020 at 12:11)</a>:</h4>
<p><span class="user-mention" data-user-id="133169">@matklad</span> just wanted to double check before merging, did you want to review the ref additions on <a href="https://github.com/rust-analyzer/rust-analyzer/pull/4743">https://github.com/rust-analyzer/rust-analyzer/pull/4743</a>? <span class="user-mention" data-user-id="129457">@Florian Diebold</span> already reviewed.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>